﻿using System;
using System.Collections;
using UnityEngine;

namespace RootMotion.FinalIK
{
	// Token: 0x020001C4 RID: 452
	public abstract class OffsetModifierVRIK : MonoBehaviour
	{
		// Token: 0x170000BE RID: 190
		// (get) Token: 0x06000958 RID: 2392 RVA: 0x00031E9A File Offset: 0x0003029A
		protected float deltaTime
		{
			get
			{
				return Time.time - this.lastTime;
			}
		}

		// Token: 0x06000959 RID: 2393
		protected abstract void OnModifyOffset();

		// Token: 0x0600095A RID: 2394 RVA: 0x00031EA8 File Offset: 0x000302A8
		protected virtual void Start()
		{
			base.StartCoroutine(this.Initiate());
		}

		// Token: 0x0600095B RID: 2395 RVA: 0x00031EB8 File Offset: 0x000302B8
		private IEnumerator Initiate()
		{
			while (this.ik == null)
			{
				yield return null;
			}
			IKSolverVR solver = this.ik.solver;
			solver.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Combine(solver.OnPreUpdate, new IKSolver.UpdateDelegate(this.ModifyOffset));
			this.lastTime = Time.time;
			yield break;
		}

		// Token: 0x0600095C RID: 2396 RVA: 0x00031ED4 File Offset: 0x000302D4
		private void ModifyOffset()
		{
			if (!base.enabled)
			{
				return;
			}
			if (this.weight <= 0f)
			{
				return;
			}
			if (this.deltaTime <= 0f)
			{
				return;
			}
			if (this.ik == null)
			{
				return;
			}
			this.weight = Mathf.Clamp(this.weight, 0f, 1f);
			this.OnModifyOffset();
			this.lastTime = Time.time;
		}

		// Token: 0x0600095D RID: 2397 RVA: 0x00031F4D File Offset: 0x0003034D
		protected virtual void OnDestroy()
		{
			if (this.ik != null)
			{
				IKSolverVR solver = this.ik.solver;
				solver.OnPreUpdate = (IKSolver.UpdateDelegate)Delegate.Remove(solver.OnPreUpdate, new IKSolver.UpdateDelegate(this.ModifyOffset));
			}
		}

		// Token: 0x04000610 RID: 1552
		[Tooltip("The master weight")]
		public float weight = 1f;

		// Token: 0x04000611 RID: 1553
		[Tooltip("Reference to the VRIK component")]
		public VRIK ik;

		// Token: 0x04000612 RID: 1554
		private float lastTime;
	}
}
